// System Unit
// Memory Manager

(*************)
(* Interface *)
(*************)
{$IFDEF Include_Modules_Header}

 Function _FreeMem(P: Pointer): Integer;
 Type RTLProc_FreeMem = Function(P: Pointer): Integer;

 Function _GetMem(Size: Integer): Pointer;
 Type RTLProc_GetMem = Function(Size: Integer): Pointer;

 Function _ReallocMem(Var P: Pointer; NewSize: Integer): Pointer;
 Type RTLProc_ReallocMem = Function(Var P: Pointer; NewSize: Integer): Pointer;

 //==================
 // RTL Extensions
 //==================
 Type
  TRTLEx_MemoryManager = Record
   _FreeMem: RTLProc_FreeMem;
   _GetMem: RTLProc_GetMem;
   _ReallocMem: RTLProc_ReallocMem;
  END;

 Procedure RTLExtend_MemoryManager(Var Ex: TRTLEx_MemoryManager);

{$ENDIF Include_Modules_Header}
(******************)
(* Implementation *)
(******************)
{$IFDEF Include_Modules_Implement}

 Function _RTL_FreeMem(P: Pointer): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_GetMem(Size: Integer): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_ReallocMem(Var P: Pointer; NewSize: Integer): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Var
  RTL_FreeMem: RTLProc_FreeMem = _RTL_FreeMem;
  RTL_GetMem: RTLProc_GetMem = _RTL_GetMem;
  RTL_ReallocMem: RTLProc_ReallocMem = _RTL_ReallocMem;

 Function _FreeMem(P: Pointer): Integer;
  ASM
   JMP RTL_FreeMem
  END;

 Function _GetMem(Size: Integer): Pointer;
  ASM
   JMP RTL_GetMem
  END;

 Function _ReallocMem(Var P: Pointer; NewSize: Integer): Pointer;
  ASM
   JMP RTL_ReallocMem
  END;

 //==================
 // RTL Extensions
 //==================

 Procedure RTLExtend_MemoryManager(Var Ex: TRTLEx_MemoryManager);
  BEGIN
   _INT_RTL_DoEx(@RTL_FreeMem, @Ex._FreeMem);
   _INT_RTL_DoEx(@RTL_GetMem, @Ex._GetMem);
   _INT_RTL_DoEx(@RTL_ReallocMem, @Ex._ReallocMem);
  END;

{$ENDIF Include_Modules_Implement}
(******************)
(* Initialization *)
(******************)
{$IFDEF Include_Modules_Initialize}
{$ENDIF Include_Modules_Initialize}
(****************)
(* Finalization *)
(****************)
{$IFDEF Include_Modules_Finalize}
{$ENDIF Include_Modules_Finalize}
